<template>
  <main-card-admin
    :title="`审核详情（${appInfo.name || ''})`"
    :crumbs="crumbs"
    :loading="loading"
    :screen-style-obj="computedScreenStyleObj"
  >
    <div class="details-content">
      <auditResult :app-info="appInfo" />
      <informationForm
        c-type="life"
        :audit-app-api="appInfo.auditAppApiVOList"
        :audit-app-sdk="appInfo.auditAppSdkVOList"
        @getClientInfo="getClientInfo()"
      />
    </div>
  </main-card-admin>
</template>

<script lang="ts" setup>
  import { computed, ref } from 'vue'
  import { useRequest } from 'vue-request'
  import { useRoute } from 'vue-router'

  import { clientApi } from '@/services/api'
  import auditResult from '@/views/admin/app-check/components/AuditResult.vue'
  import informationForm from '@/views/admin/app-check/components/InformationForm.vue'
  import { AuditDetails } from '@/views/admin/app-check/types'

  const route = useRoute()

  const { id } = route.params as { id: string }

  const crumbs = computed(() => {
    return [
      isAdmin.value
        ? {
            name: '管理员',
            path: '/user-manage/admin-list'
          }
        : {
            name: '普通用户',
            path: '/user-manage/student-list'
          },
      {
        name: `账号详情（${appInfo.value.username || ''}）`,
        path: `/user-manage/detail/${appInfo.value.uid}`
      },

      { name: `审核详情（${appInfo.value.name || ''})` }
    ]
  })
  const computedScreenStyleObj = computed(() => {
    return {
      padding: '0 32px 0 32px'
    }
  })
  const appInfo = ref<AuditDetails>({})

  const { loading, runAsync: getClientInfo } = useRequest<any>(clientApi.lifecycleDetailsType3(id), {
    onSuccess: res => {
      Object.assign(appInfo.value, res.data)
      getUserIsAdmin(appInfo.value.uid)
    },
    onError: () => {}
  })
  /* 用户详情-------------------------------------------------------------------- */
  const isAdmin = ref(false)

  /**
   * 获取用户是否管理员（用于更改面包屑）
   * @param id
   */
  const getUserIsAdmin = async (id: string) => {
    const { data } = await clientApi.detail(id)()
    isAdmin.value = data.roleType === 2
  }
</script>
<style lang="less" scoped>
  .details-content {
    position: relative;
    display: flex;
    margin: 0 auto;
    width: 864px;
    background: #fff;
    border-radius: 6px;
    flex-direction: column;
    gap: 24px;
  }
</style>
